* This do-file makes "Table 1. Baseline Balance"
* File written by Kazuma Takakura kazuma.arukakat@gmail.com (University of Tokyo)
* Last updated on April 27, 2024


set more off

use "$path_data/fninvest_experience.dta", clear

   gen risk10_1std_yes = risk10_1std*fn8500
   gen risk10_1std_no = risk10_1std*(1-fn8500)
   gen cc00_yes = cc00*fn8500
   gen cc00_no = cc00*(1-fn8500)
   gen success00_yes = success00*fn8500
   gen success00_no = success00*(1-fn8500)
   gen hyper_yes = hyper10 * fn8500
   gen hyper_no = hyper10 * (1-fn8500)
   gen hyper1_yes = hyper10_1 * fn8500
   gen hyper1_no = hyper10_1 * (1-fn8500)
   gen hyper2_yes = hyper10_2 * fn8500
   gen hyper2_no = hyper10_2 * (1-fn8500)
   gen inconsistent = 1 if hyper10_1==1 & hyper10_2==0
   recode inconsistent(.=0)
   gen highdisc_yes = highdisc10 * fn8500
   gen highdisc_no = highdisc10 * (1-fn8500)
   gen age_yes = age_old*fn8500+10
   gen age_no = age_old*(1-fn8500)+10
   gen age2_yes = age_yes^2
   gen age2_no = age_no^2
   gen high_edu_yes = high_edu*fn8500
   gen high_edu_no = high_edu*(1-fn8500)
   gen high_edu2_yes = high_edu_yes^2
   gen high_edu2_no = high_edu_no^2
   gen risk10_2std_yes = risk10_2std*fn8500
   gen risk10_2std_no = risk10_2std*(1-fn8500)
   gen risk10_3std_yes = risk10_3std*fn8500
   gen risk10_3std_no = risk10_3std*(1-fn8500)
   gen house_yes = house * fn8500
   gen house_no = house * (1-fn8500)
   gen land_yes = land * fn8500
   gen land_no = land * (1-fn8500)
   gen houseland_yes = houseland * fn8500
   gen houseland_no = houseland * (1-fn8500)
   gen landinh_yes = land_inherit * fn8500
   gen landinh_no = land_inherit * (1-fn8500)
   gen house_or_land_yes = house_or_land * fn8500
   gen house_or_land_no = house_or_land * (1-fn8500)
   gen landall_yes = land_all * fn8500
   gen landall_no = land_all * (1-fn8500)
   gen numhh_yes = numhh * fn8500
   gen numhh_no = numhh * (1-fn8500)
   gen numhh2_yes = numhh_yes^2
   gen numhh2_no = numhh_no^2


/// (1)
reg fn8500 houseland village risk00_1std success85 hyper00 highdisc00 high_edu high_edu2 cc85std land_all land_inherit, robust
matrix first_1 = r(table)

forval i =1/15{
scalar v1_mean = first_1[1,1]
scalar v1_var = (first_1[2,1])^2
}


predict pred
gen error = fn8500-pred
sum pred
scalar gamma_min = r(min)
scalar gamma_max = r(max)
scalar gamma_mean = r(mean)
scalar gamma_var = r(Var)
drop pred
sum error
scalar u_min = r(min)
scalar u_max = r(max)
scalar u_mean = r(mean)
scalar u_var = r(Var)
drop error


program olsen8500
gen gamma = rnormal(gamma_mean, gamma_var)
gen fn8500_yes = (gamma-1)*fn8500 
gen fn8500_no = (-1)*gamma*(1-fn8500)
reg fn0010 houseland_yes houseland_no landall_yes landall_no landinh_yes landinh_no success00_yes success00_no risk10_1std_yes risk10_1std_no hyper1_yes hyper1_no highdisc_yes highdisc_no high_edu_yes high_edu_no high_edu2_yes high_edu2_no fn8500_yes fn8500_no cc00_yes cc00_no crra5_g1_dominated village riceland riceland2, robust
drop gamma fn8500_yes fn8500_no
   end program
eststo: bootstrap, reps(1000) seed(1) : olsen8500
matrix result_85_2 = r(table)
scalar Rsquared_85_2 = e(r2_a)

/// (2)

reg fn8500 houseland land_all land_inherit risk00_1std success85 hyper00 highdisc00 high_edu high_edu2 cc85std age_old numhh village age_missing numhh_missing, robust
predict pred
gen error = fn8500-pred
sum pred
scalar gamma_min = r(min)
scalar gamma_max = r(max)
scalar gamma_mean = r(mean)
scalar gamma_var = r(Var)
drop pred
sum error
scalar u_min = r(min)
scalar u_max = r(max)
scalar u_mean = r(mean)
scalar u_var = r(Var)
drop error

program olsen8500_age
gen gamma = rnormal(gamma_mean, gamma_var)
gen fn8500_yes = (gamma-1)*fn8500 
gen fn8500_no = (-1)*gamma*(1-fn8500)
reg fn0010 houseland_yes houseland_no landall_yes landall_no landinh_yes landinh_no success00_yes success00_no risk10_1std_yes risk10_1std_no hyper1_yes hyper1_no highdisc_yes highdisc_no high_edu_yes high_edu_no high_edu2_yes high_edu2_no fn8500_yes fn8500_no cc00_yes cc00_no age_old numhh age_missing numhh_missing crra5_g1_dominated village riceland riceland2, robust
drop gamma fn8500_yes fn8500_no
end program
eststo: bootstrap, reps(1000) seed(1) : olsen8500_age
matrix result_85_3 = r(table)
scalar Rsquared_85_3 = e(r2_a)


/// (3)

reg fn8500 house land_all land_inherit risk00_1std success85 hyper00 highdisc00 high_edu high_edu2 cc85std age_old age_old2 numhh numhh2 village age_missing numhh_missing, robust
predict pred
gen error = fn8500-pred
sum pred
scalar gamma_min = r(min)
scalar gamma_max = r(max)
scalar gamma_mean = r(mean)
scalar gamma_var = r(Var)
drop pred
sum error
scalar u_min = r(min)
scalar u_max = r(max)
scalar u_mean = r(mean)
scalar u_var = r(Var)
drop error

program olsen8500_agesquared
gen gamma = rnormal(gamma_mean, gamma_var)
gen fn8500_yes = (gamma-1)*fn8500 
gen fn8500_no = (-1)*gamma*(1-fn8500)
reg fn0010 houseland_yes houseland_no landall_yes landall_no landinh_yes landinh_no success00_yes success00_no risk10_1std_yes risk10_1std_no hyper1_yes hyper1_no highdisc_yes highdisc_no high_edu_yes high_edu_no high_edu2_yes high_edu2_no fn8500_yes fn8500_no cc00_yes cc00_no age_old age_old2 numhh numhh2 age_missing numhh_missing crra5_g1_dominated village riceland riceland2, robust
drop gamma fn8500_yes fn8500_no
end program
eststo: bootstrap, reps(1000) seed(1) : olsen8500_agesquared
matrix result_85_4 = r(table)
scalar Rsquared_85_4 = e(r2_a)


/// (4)

reg fn8500 house land_all land_inherit risk00_1std success85 hyper00 highdisc00 high_edu high_edu2 cc85std village age20s age30s age40s age50s age60s age70s age80s numhh13 numhh46 numhh79 numhh1013 age_missing numhh_missing, robust
predict pred
gen error = fn8500-pred
sum pred
scalar gamma_min = r(min)
scalar gamma_max = r(max)
scalar gamma_mean = r(mean)
scalar gamma_var = r(Var)
drop pred
sum error
scalar u_min = r(min)
scalar u_max = r(max)
scalar u_mean = r(mean)
scalar u_var = r(Var)
drop error

program olsen8500_agedummy
gen gamma = rnormal(gamma_mean, gamma_var)
gen fn8500_yes = (gamma-1)*fn8500 
gen fn8500_no = (-1)*gamma*(1-fn8500)
reg fn0010 houseland_yes houseland_no landall_yes landall_no landinh_yes landinh_no success00_yes success00_no risk10_1std_yes risk10_1std_no hyper1_yes hyper1_no highdisc_yes highdisc_no high_edu_yes high_edu_no high_edu2_yes high_edu2_no fn8500_yes fn8500_no cc00_yes cc00_no age20s age30s age40s age50s age60s age70s age80s numhh13 numhh46 numhh79 numhh1013 age_missing numhh_missing crra5_g1_dominated village riceland riceland2, robust
drop gamma fn8500_yes fn8500_no
end program
eststo: bootstrap, reps(1000) seed(1) : olsen8500_agedummy
matrix result_85_5 = r(table)
scalar Rsquared_85_5 = e(r2_a)




forvalues n = 2/5 {
forvalues item = 4/4 {
		forvalues scale = 1/28 {
		if result_85_`n'[`item', `scale']<=0.01 {
			local star85_`n'_`scale' %3s "***"
		}
		else if (result_85_`n'[`item', `scale']>0.01) & (result_85_`n'[`item', `scale']<=0.05) {
			local star85_`n'_`scale' %2s "**"
		}
		else if (result_85_`n'[`item', `scale']>0.05) & (result_85_`n'[`item', `scale']<=0.10) {
			local star85_`n'_`scale' %1s "*"
		}
		else {
			local star85_`n'_`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop


} // forvalues `n' loop



tempname hh2
file open `hh2' using "$path_tex/Table_second_8500.tex", write replace
file write `hh2' "" _newline
file write `hh2' "% Author: Kazuma Takakura" _newline
file write `hh2' "% Date: `c(current_date)'" _newline
file write `hh2' "% Time: `c(current_time)'" _newline
file write `hh2' "" _newline


file write `hh2' "\begin{table}[h!]\footnotesize" _newline
file write `hh2' "  \centering" _newline
file write `hh2' "  \caption{Second-stage technology adoption, 2000-2010}" _newline
file write `hh2' "\label{tab:secondphase}" _newline
file write `hh2' "\scalebox{0.9}{" _newline
file write `hh2' "\begin{threeparttable}" _newline

file write `hh2' "\begin{tabular}{lcccccccc}\toprule" _newline
file write `hh2' "& \multicolumn{2}{c}{(1)} & \multicolumn{2}{c}{(2)} & \multicolumn{2}{c}{(3)} & \multicolumn{2}{c}{(4)} \\" _newline
file write `hh2' "Decision at First Phase& D_1=1 & D_1=0 & D_1=1 & D_1=0 & D_1=1 & D_1=0 & D_1=1 & D_1=0 \\\midrule\midrule" _newline
file write `hh2' "  Displacement (dummy) & " %04.3f (result_85_2[1,1]) `star85_2_1' " & " %04.3f (result_85_2[1,2]) `star85_2_2' " & " %04.3f (result_85_3[1,1]) `star85_3_1' " & " %04.3f (result_85_3[1,2]) `star85_3_2' " & " %04.3f (result_85_4[1,1]) `star85_4_1' " & " %04.3f (result_85_4[1,2]) `star85_4_2' " & " %04.3f (result_85_5[1,1]) `star85_5_1' " & " %04.3f (result_85_5[1,2]) `star85_5_2' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,1]) ") & (" %04.3f (result_85_2[2,2]) ") &(" %04.3f (result_85_3[2,1]) ")&(" %04.3f (result_85_3[2,2]) ") &(" %04.3f (result_85_4[2,1]) ")&(" %04.3f (result_85_4[2,2]) ") &(" %04.3f (result_85_5[2,1]) ")&(" %04.3f (result_85_5[2,2]) ") \\" _newline
file write `hh2' "  Land loss (dummy) & " %04.3f (result_85_2[1,3]) `star85_2_3' " & " %04.3f (result_85_2[1,4]) `star85_2_4' "& " %04.3f (result_85_3[1,3]) `star85_3_3' "& " %04.3f (result_85_3[1,4]) `star85_3_4' "& " %04.3f (result_85_4[1,3]) `star85_4_3' "& " %04.3f (result_85_4[1,4]) `star85_4_4' " & " %04.3f (result_85_5[1,3]) `star85_5_3' "& " %04.3f (result_85_5[1,4]) `star85_5_4' "\\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,3]) ") & (" %04.3f (result_85_2[2,4]) ") &(" %04.3f (result_85_3[2,3]) ")&(" %04.3f (result_85_3[2,4]) ")&(" %04.3f (result_85_4[2,3]) ")&(" %04.3f (result_85_4[2,4]) ")&(" %04.3f (result_85_5[2,3]) ")&(" %04.3f (result_85_5[2,4]) ") \\" _newline
file write `hh2' "  Land owner (dummy) & " %04.3f (result_85_2[1,5]) `star85_2_5' " & " %04.3f (result_85_2[1,6]) `star85_2_6' "& " %04.3f (result_85_3[1,5]) `star85_3_5' "& " %04.3f (result_85_3[1,6]) `star85_3_6' "& " %04.3f (result_85_4[1,5]) `star85_4_5' "& " %04.3f (result_85_4[1,6]) `star85_4_6' " & " %04.3f (result_85_5[1,5]) `star85_5_5' "& " %04.3f (result_85_5[1,6]) `star85_5_6' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,5]) ") & (" %04.3f (result_85_2[2,6]) ")&(" %04.3f (result_85_3[2,5]) ")&(" %04.3f (result_85_3[2,6]) ")&(" %04.3f (result_85_4[2,5]) ")&(" %04.3f (result_85_4[2,6]) ")&(" %04.3f (result_85_5[2,5]) ")&(" %04.3f (result_85_5[2,6]) ")\\" _newline
file write `hh2' "  Number of success in 2000  & " %04.3f (result_85_2[1,7]) `star85_2_7' "& " %04.3f (result_85_2[1,8]) `star85_2_8' "& " %04.3f (result_85_3[1,7]) `star85_3_7' "& " %04.3f (result_85_3[1,8]) `star85_3_8' "& " %04.3f (result_85_4[1,7]) `star85_4_7' "& " %04.3f (result_85_4[1,8]) `star85_4_8' " & " %04.3f (result_85_5[1,7]) `star85_5_7' "& " %04.3f (result_85_5[1,8]) `star85_5_8' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,7]) ")& (" %04.3f (result_85_2[2,8]) ")&(" %04.3f (result_85_3[2,7]) ")&(" %04.3f (result_85_3[2,8]) ")&(" %04.3f (result_85_4[2,7]) ")&(" %04.3f (result_85_4[2,8]) ")&(" %04.3f (result_85_5[2,7]) ")&(" %04.3f (result_85_5[2,8]) ") \\" _newline
file write `hh2' "  Risk aversion in 2010 & " %04.3f (result_85_2[1,9]) `star85_2_9' " & " %04.3f (result_85_2[1,10]) `star85_2_10' "& " %04.3f (result_85_3[1,9]) `star85_3_9' "& " %04.3f (result_85_3[1,10]) `star85_3_10' "& " %04.3f (result_85_4[1,9]) `star85_4_9' "& " %04.3f (result_85_4[1,10]) `star85_4_10' " & " %04.3f (result_85_5[1,9]) `star85_5_9' "& " %04.3f (result_85_5[1,10]) `star85_5_10' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,9]) ")& (" %04.3f (result_85_2[2,10]) ")&(" %04.3f (result_85_3[2,9]) ")&(" %04.3f (result_85_3[2,10]) ")&(" %04.3f (result_85_4[2,9]) ")&(" %04.3f (result_85_4[2,10]) ")&(" %04.3f (result_85_5[2,9]) ")&(" %04.3f (result_85_5[2,10]) ") \\" _newline
file write `hh2' "  Hyperbolistic discounting in 2010   & " %04.3f (result_85_2[1,11]) `star85_2_11' "& " %04.3f (result_85_2[1,12]) `star85_2_12' "& " %04.3f (result_85_3[1,11]) `star85_3_11' "& " %04.3f (result_85_3[1,12]) `star85_3_12' "& " %04.3f (result_85_4[1,11]) `star85_4_11' "& " %04.3f (result_85_4[1,12]) `star85_4_12' " & " %04.3f (result_85_5[1,11]) `star85_5_11' "& " %04.3f (result_85_5[1,12]) `star85_5_12' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,11]) ")& (" %04.3f (result_85_2[2,12]) ")&(" %04.3f (result_85_3[2,11]) ")&(" %04.3f (result_85_3[2,12]) ")&(" %04.3f (result_85_4[2,11]) ")&(" %04.3f (result_85_4[2,12]) ")&(" %04.3f (result_85_5[2,11]) ")&(" %04.3f (result_85_5[2,12]) ") \\" _newline
file write `hh2' "  High discounting in 2010 & " %04.3f (result_85_2[1,13]) `star85_2_13' "& " %04.3f (result_85_2[1,14]) `star85_2_14' "& " %04.3f (result_85_3[1,13]) `star85_3_13' "& " %04.3f (result_85_3[1,14]) `star85_3_14' "& " %04.3f (result_85_4[1,13]) `star85_4_13' "& " %04.3f (result_85_4[1,14]) `star85_4_14' " & " %04.3f (result_85_5[1,13]) `star85_5_13' "& " %04.3f (result_85_5[1,14]) `star85_5_14' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,13]) ")& (" %04.3f (result_85_2[2,14]) ")&(" %04.3f (result_85_3[2,13]) ")&(" %04.3f (result_85_3[2,14]) ")&(" %04.3f (result_85_4[2,13]) ")&(" %04.3f (result_85_4[2,14]) ")&(" %04.3f (result_85_5[2,13]) ")&(" %04.3f (result_85_5[2,14]) ") \\" _newline
file write `hh2' "  Years of education & " %04.3f (result_85_2[1,15]) `star85_2_15' "& " %04.3f (result_85_2[1,16]) `star85_2_16' "& " %04.3f (result_85_3[1,15]) `star85_3_15' "& " %04.3f (result_85_3[1,16]) `star85_3_16' "& " %04.3f (result_85_4[1,15]) `star85_4_15' "& " %04.3f (result_85_4[1,16]) `star85_4_16' " & " %04.3f (result_85_5[1,15]) `star85_5_15' "& " %04.3f (result_85_5[1,16]) `star85_5_16' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,15]) ")& (" %04.3f (result_85_2[2,16]) ")&(" %04.3f (result_85_3[2,15]) ")&(" %04.3f (result_85_3[2,16]) ")&(" %04.3f (result_85_4[2,15]) ")&(" %04.3f (result_85_4[2,16]) ")&(" %04.3f (result_85_5[2,15]) ")&(" %04.3f (result_85_5[2,16]) ")\\" _newline
file write `hh2' "  Years of education squared & " %04.3f (result_85_2[1,17]) `star85_2_17' " & " %04.3f (result_85_2[1,18]) `star85_2_18' "& " %04.3f (result_85_3[1,17]) `star85_3_17' "& " %04.3f (result_85_3[1,18]) `star85_3_18' "& " %04.3f (result_85_4[1,17]) `star85_4_17' "& " %04.3f (result_85_4[1,18]) `star85_4_18' " & " %04.3f (result_85_5[1,17]) `star85_5_17' "& " %04.3f (result_85_5[1,18]) `star85_5_18' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,17]) ") & (" %04.3f (result_85_2[2,18]) ")&(" %04.3f (result_85_3[2,17]) ")&(" %04.3f (result_85_3[2,18]) ")&(" %04.3f (result_85_4[2,17]) ")&(" %04.3f (result_85_4[2,18]) ")&(" %04.3f (result_85_5[2,17]) ")&(" %04.3f (result_85_5[2,18]) ")\\" _newline
file write `hh2' "  Credit constraint in 2000 & " %04.3f (result_85_2[1,21]) `star85_2_21' " & " %04.3f (result_85_2[1,22]) `star85_2_22' "& " %04.3f (result_85_3[1,21]) `star85_3_21' "& " %04.3f (result_85_3[1,22]) `star85_3_22' "& " %04.3f (result_85_4[1,21]) `star85_4_21' "& " %04.3f (result_85_4[1,22]) `star85_4_22' " & " %04.3f (result_85_5[1,21]) `star85_5_21' "& " %04.3f (result_85_5[1,22]) `star85_5_22' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,21]) ") & (" %04.3f (result_85_2[2,22]) ")&(" %04.3f (result_85_3[2,21]) ")&(" %04.3f (result_85_3[2,22]) ")&(" %04.3f (result_85_4[2,21]) ")&(" %04.3f (result_85_4[2,22]) ")&(" %04.3f (result_85_5[2,21]) ")&(" %04.3f (result_85_5[2,22]) ")\\" _newline
file write `hh2' "  $\delta$ & " %04.3f (result_85_2[1,19]) `star85_2_19' " & " %04.3f (result_85_2[1,20]) `star85_2_20' "& " %04.3f (result_85_3[1,19]) `star85_3_19' "& " %04.3f (result_85_3[1,20]) `star85_3_20' "& " %04.3f (result_85_4[1,19]) `star85_4_19' "& " %04.3f (result_85_4[1,20]) `star85_4_20' " & " %04.3f (result_85_5[1,19]) `star85_5_19' "& " %04.3f (result_85_5[1,20]) `star85_5_20' " \\" _newline
file write `hh2' "    & (" %04.3f (result_85_2[2,19]) ") & (" %04.3f (result_85_2[2,20]) ")&(" %04.3f (result_85_3[2,19]) ")&(" %04.3f (result_85_3[2,20]) ")&(" %04.3f (result_85_4[2,19]) ")&(" %04.3f (result_85_4[2,20]) ")&(" %04.3f (result_85_5[2,19]) ")&(" %04.3f (result_85_5[2,20]) ")\\" _newline
file write `hh2' "  Head's age & & & X & X & X & X & & \\" _newline
file write `hh2' "  Household size & & & X & X & X & X & & \\" _newline
file write `hh2' "  Head's age squared & & & & & X & X & &  \\" _newline
file write `hh2' "  Household size squared & & & & & X & X & &  \\" _newline
file write `hh2' "  Head's age dummy (by 10 years each) & & & & & & & X & X \\" _newline
file write `hh2' "  Household size dummy (by 3 people each) & & & & & & & X & X \\" _newline

file write `hh2' "   Adjusted R$^2$ & \multicolumn{2}{c}{ " %04.3f (Rsquared_85_2) " } & \multicolumn{2}{c}{ " %04.3f (Rsquared_85_3) " } & \multicolumn{2}{c}{ " %04.3f (Rsquared_85_4) " } & \multicolumn{2}{c}{ " %04.3f (Rsquared_85_5) " } \\ " _newline
file write `hh2' "  Observations & \multicolumn{2}{c}{399} & \multicolumn{2}{c}{399} & \multicolumn{2}{c}{399} & \multicolumn{2}{c}{399} \\ " _newline
file write `hh2' "  (Observations conditional on the first-phase decision) & (254)  & (145) & (254)  & (145) & (254)  & (145) & (254)  & (145) \\ " _newline


file write `hh2' "\\\midrule" _newline
file write `hh2' "\end{tabular}" _newline
file write `hh2' "\begin{tablenotes}" _newline
file write `hh2' "\item \textsuperscript{a}: The procedure was bootstraped 1000 times." _newline
file write `hh2' "\item \textsuperscript{b}: Controls: area of farmland, squared area of farmland, village dummy, age missing dummy, and number of household missing dummy." _newline
file write `hh2' "\item \textsuperscript{b}: The asterisks ***, **, and * denote the 1 percent, 5 percent, and 10 percent levels of significance, respectively." _newline
file write `hh2' "" _newline
file write `hh2' "\end{tablenotes}" _newline
file write `hh2' "\end{threeparttable}" _newline
file write `hh2' "}" _newline
file write `hh2' "\label{tab:addlabel}%" _newline
file write `hh2' "\end{table}" _newline

file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline

file close `hh2'
